define([
        'app/utils/WeixinUtils',
        'text!app/tpl/login.html',
        'app/service/LoginService',
        'app/directive/LoginDirective'
        
        ], function (
        WeixinUtils,
        loginTpl,
        LoginService,
        LoginDirective
    ) {

    

    var controller = function () {

        //0. Weixin Disabled
        WeixinUtils.disableAll();

        
        //1. Data Initialized
        LoginService.init(function(resp){
            
            if($.isNull(resp)){
                $.redirectTo($.wjtBaseBackend + "/mvc/authorize?state=login");
                return;
            }

            if(resp.status!="200"){
                $.redirectTo($.wjtBaseBackend + "/mvc/authorize?state=login");
                return;
            }

            //2. Weixin Initialized
            WeixinUtils.disableAll();


            //3. tpl Initialized - Never change!!!
            var tpl = WebUtils.tplInitialized();

            //4. UI Initialized
            var loginUI = _.template(loginTpl)({
                "headImageUrl": resp.result.frontUser.headImageUrl,
                "name": resp.result.frontUser.name,
                "tel": resp.result.frontUser.tel,
                "uuid": resp.result.frontUser.uuid,
                "weixinavatarUrl": resp.result.weixinavatarUrl
            });
           

            //4. Assemble
            tpl.append(loginUI);

            //5. Render - Never change!!!
            WebUtils.render(tpl);

            //6. Directive initialized
            LoginDirective.directive_inputName();
            LoginDirective.directive_inputTel();
            LoginDirective.directive_avatar1();
            LoginDirective.directive_login1();
            LoginDirective.directive_weixinavatar();
            

        })
        


        //7. routechange - Never change!!!
        controller.onRouteChange = WebUtils.routeChange;

    };

    return controller;


});
